import json
import pandas as pd

with open('citydemo.json', 'r', encoding='utf-8') as file:
    data = json.load(file)

top_all=[]
for city in data["cityList"]:
    top = {} #top每次都更新，添加下一个字典的前五个键值
    count = 0

    for i, j in city.items():
        if count < 5:
            top[i] = j
            count += 1
        else:
            break
    print(top)
    top_all.append(top)

print("\n--------------")
print(top_all)

df = pd.DataFrame(top_all)

df.to_excel('work_2.xlsx', index=False)